//
//  MYXMainViewController.swift
//  weibo
//
//  Created by MaYingxin on 16/4/17.
//  Copyright © 2016年 MaYingxin. All rights reserved.
//

import UIKit

class MYXMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = MYXTabBar()
        
        tabBar.delegate = self
        
        setValue(tabBar, forKey: "tabBar")
        
        
        
        
        
        addChildViewController(MYXHomeViewController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(MYXMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(MYXMessageViewController(), imgName: "tabbar_home", title: nil)
        
        addChildViewController(MYXDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(MYXProfileViewController(), imgName: "tabbar_profile", title: "我的")
        

        print(tabBar.subviews.count)
        
    }
    
    func addChildViewController(childController: UIViewController?, imgName: String?, title: String?) {
     
        childController?.tabBarItem.image = UIImage(named: (imgName ?? ""))
        
        childController!.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
        childController?.title = title
        
        
        addChildViewController(UINavigationController(rootViewController: childController!))
        
    }
}

extension MYXMainViewController: MYXTabBarDelegate{
    
    func composeClick() {
        
        print("composeClick by MYXMainViewController")
    }
}




